#!/bin/bash

ISO_TYPE='i686'
MODE='wipe'


((`id -u`)) && echo "This script must be run as user 'root'" && exit
#if [[ ${EUID} -ne 0 ]]; then

while mount | grep ./work/efiboot ; do umount ./work/efiboot ; sleep 1 ; done ;

if [ "$MODE" == 'wipe' ] # total wipe (preserving package cache)
then if [ -d ./work/$ISO_TYPE/root-image/isorepo/ ]
     then mv ./work/$ISO_TYPE/root-image/isorepo/ .
          rm -rf ./work/
          mkdir -p ./work/$ISO_TYPE/root-image/
          mv ./isorepo ./work/$ISO_TYPE/root-image/
     else rm -rf ./work/ 2> /dev/null
     fi

elif [ "$MODE" == 'rebuild' ] # full rebuild
then rm -v ./work/build.make_*

elif [ "$MODE" == 'tweak' ] # tweaks only
then rm work/build.make_customize_root_image_$ISO_TYPE \
        work/build.make_prepare_$ISO_TYPE              \
        work/build.make_iso*                           2> /dev/null
fi
# ./build.sh -v -T $ISO_TYPE -V "`date +%Y.%m.%d-%H.%M`-alpha"
./build.sh -v -O -T $ISO_TYPE -V "`date +%Y.%m.%d-%H.%M`-alpha"
